<template>
  <div style="border: solid 20px rgb(245, 247, 249)">
    <Button
      style="color: aliceblue; margin: 20px"
      icon="ivu-icon ivu-icon-md-add"
      type="primary"
      @click="modal = true"
      >新增</Button
    >
    <Table border :columns="columns" :data="watchList">
      <template #name="{ row }">
        <strong>{{ row.name }}</strong>
      </template>
      <template #action="{ index }">
        <Button type="error" size="small" @click="remove(index)">删除</Button>
      </template>
    </Table>
    <Modal
      v-model="modal"
      title="管理优惠"
      :loading="loading"
      @on-ok="asyncOK(true)"
      class="inp1"
    >
      优惠名称:<Input
        v-model="this.watchList.name"
        placeholder="分类名称"
        style="width: 400px; margin: 10px"
      />
      优惠ID:<Input
        v-model="this.watchList._id"
        placeholder="排序"
        style="width: 420px; margin: 10px"
      />
      流水号:<Input
        v-model="this.watchList.available"
        placeholder="排序"
        style="width: 400px; margin: 10px"
      />
      <!-- <Ipload @getUrl="zz"></Ipload> -->
    </Modal>
  </div>
</template>
<script>
// import Ipload from "../../components/Upload.vue"
// import list from "../../Api/fund.js"
export default {
  // components: { Ipload },
  created() {
    this.$axios
      .get("http://unicloud.codecore.cn/admin/couponList")
      .then((res) => {
        this.watchList = res.data.data;
        console.log(this.watchList);
      });
  },
  data() {
    return {
      modal: false,
      columns: [
        {
          title: "优惠",
          key: "name",
        },
        {
          title: "id",
          key: "condition",
        },
        {
          title: "订单创建时间",
          key: "end",
        },
        {
          title: "流水号",
          key: "available",
        },
        {
          title: "完成支付时间",
          key: "start",
        },
        {
          title: "操作",
          slot: "action",
          width: 150,
          align: "center",
        },
      ],
      watchList: [],
    };
  },
  methods: {
    remove(index) {
      this.$axios.post("http://unicloud.codecore.cn/admin/couponDelete",{_id:this.watchList[index]._id}).then((res)=>{
        console.log(res);
      })
      this.watchList.splice(index, 1);
    },
  },
};
</script>